<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
      <el-form-item label="任务ID" prop="taskId">
        <el-input v-model="queryParams.taskId" placeholder="请输入任务ID" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>


      <el-form-item label="任务标题" prop="taskName">
        <el-input v-model="queryParams.taskName" placeholder="请输入任务标题" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="任务类型" prop="typeId">

        <el-select v-model="queryParams.typeId" placeholder="选择任务分类" clearable size="small" style="width: 200px">
          <el-option v-for="item in classification" :key="item.value" :label="item.typeName" :value="item.typeId" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索
        </el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置
        </el-button>

      </el-form-item>
    </el-form>
    <br />
    <el-row :span="24">
      <el-col :span="12">
        <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd('add')">发布</el-button>
      </el-col>


    </el-row>

    <br />

    <el-table v-loading="loading" :data="rewardList" @selection-change="handleSelectionChange">
      <el-table-column label="任务ID" align="center" prop="taskId" />
      <el-table-column label="任务名称" align="center" prop="taskName" />
      <el-table-column label="任务图标" align="center" prop="taskNum">
        <template slot-scope="scope">
          <el-image style="width: 100px; height: 100px; margin: 5px" :src="requestUrl + '' + scope.row.taskIcon"
            :preview-src-list="[requestUrl + '' + scope.row.taskIcon]">
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="任务分类" align="center" prop="typeName" />
      <el-table-column label="任务标签" align="center" prop="taskLabelList">
        <template slot-scope="scope">
          <el-tag v-for="(item, index) in scope.row.taskLabelList" :key="index" style=" margin: 5px;">
            {{ item }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="预计完成时长" align="center" prop="finishMins" />
      <el-table-column label="提交时长" align="center" prop="submitMins" />
      <el-table-column label="补交时长" align="center" prop="resubmitMins" />
      <el-table-column label="排序" align="center" prop="sortNum" />
      <el-table-column label="是否上架" align="center">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.status" :active-value="1" :inactive-value="0"
            @change="recommendChange(scope.row)">
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="任务数量" align="center" prop="taskNum" />
      <el-table-column label="任务金额" align="center" prop="rewardAmt" />
      <el-table-column label="发布时间" align="center" prop="createTime" />

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)">详情
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleAdd('edit', scope.row)">编辑
          </el-button>
          <el-button v-if="scope.row.userId !== 1" size="mini" type="text" icon="el-icon-delete"
            @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 详情 -->

    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body @close="cancel">
      <el-form ref="form" :model="form" label-width="80px">
        <el-row :span="24">
          <el-col :span="12">
            <el-form-item label="任务名称：" label-width="140px">
              <span>{{ form.taskName }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="分类名称：" label-width="140px">
              <span>{{ form.typeName }}</span>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="任务数量:" label-width="140px">
              <span>{{ form.taskNum }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="奖励金额:" label-width="140px">
              <span>{{ form.rewardAmt }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="提交时长（分钟）:" label-width="140px">
              <span>{{ form.submitMins }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="补交时长（分钟）:" label-width="140px">
              <span>{{ form.resubmitMins }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="预计完成时间（分钟）:" label-width="160px">
              <span>{{ form.finishMins }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="排序:" label-width="140px">
              <span>{{ form.sortNum }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="上架状态:" label-width="140px">
              <span>{{ form.status == 1 ? '上架' : '下架' }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="任务标签:" label-width="140px">
              <span v-for="(item, index) in form.taskLabelList" :key="index">{{ item }}{{
                index + 1 == form.taskLabelList.length ? '' : ',' }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="排序:" label-width="140px">
              <span>{{ form.sortNum }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="任务图标:" label-width="140px">
              <el-image style="width: 100px; height: 140px; margin: 5px" :src="requestUrl + '' + form.taskIcon"
                :preview-src-list="[requestUrl + '' + form.taskIcon]">
              </el-image>
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item label="任务要求:" label-width="140px">
              <div v-html="form.taskDemand" class="eitd"></div>
            </el-form-item>
          </el-col>
          <el-col :span="24">

            <el-form-item label="任务步骤:" label-width="140px">
              <p class="eitd" v-html="form.taskStep" style="white-space:pre-wrap;margin-top:0px;"></p>


            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="官方要求:" label-width="140px">
              <p class="eitd" v-html="form.taskTips" style="white-space:pre-wrap;margin-top:0px;"></p>

            </el-form-item>
          </el-col>

          <el-col :span="24">

            <el-form-item label="交单格式:" label-width="140px">
              <p class="eitd" v-html="form.taskFormat" style="white-space:pre-wrap;margin-top:0px;"></p>

            </el-form-item>
          </el-col>

        </el-row>
        <el-form-item label="任务二维码:" label-width="140px">
          <el-image style="width: 100px; height: 140px; margin: 5px" :src="requestUrl + '' + form.taskQrCode"
            :preview-src-list="[requestUrl + '' + form.taskQrCode]">
          </el-image>
        </el-form-item>

        <el-form-item label="任务示例图：" label-width="140px">
          <el-image v-for="(item, index) in form.taskImageList" :key="index"
            style="width: 100px; height: 140px; margin: 5px" :src="item" :preview-src-list="form.taskImageList">
          </el-image>
        </el-form-item>

        <!-- <el-form-item label="视频" label-width="140px">
          <a :href="form.videoPath" target="_blank" style="color: #337ab7" v-if="form.videoPath">
            查看视频
          </a>
        </el-form-item> -->




        <el-form-item label="任务描述：" label-width="140px">
          <span>{{ form.description ? form.description : "无" }}</span>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="submit">确认</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!-- 新增/修改 -->
    <el-dialog :title="title" :visible.sync="addopen" width="1000px" append-to-body @close="cancel2">
      <el-form ref="formadd" :model="formadd" label-width="120px">
        <el-row :span="24">
          <el-col :span="8">
            <el-form-item label="任务分类：" prop="typeId" :rules="[
              { required: true, message: '请选择任务分类', trigger: 'blur' },
            ]">
              <el-select v-model="formadd.typeId" placeholder="选择任务分类" clearable size="small" style="width: 200px">
                <el-option v-for="item in classification" :key="item.value" :label="item.typeName" :value="item.typeId" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="任务名称：" prop="taskName" :rules="[
              { required: true, message: '请输入任务名称', trigger: 'blur' },
            ]">
              <el-input v-model="formadd.taskName" placeholder="请输入任务名称" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="数量：" prop="taskNum" :rules="taskNumRules">
              <el-input v-model="formadd.taskNum" placeholder="请输入数量" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="任务图标:" prop="taskIcon" :rules="[
              { required: true, message: '请上传任务图标', trigger: 'blur' },
            ]">
              <imageUpload :limit="1" :file-size="3" v-model="formadd.taskIcon" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="任务标签：" prop="taskLabelList" :rules="[
              { required: true, message: '请输入任务标签', trigger: 'blur' },
            ]">
              <el-tag :key="tag" style="margin-right: 10px;" v-for="tag in dynamicTags" closable
                :disable-transitions="false" @close="handleClose(tag)">
                {{ tag }}
              </el-tag>
              <el-input class="input-new-tag" v-if="inputVisible" v-model="inputValue" ref="saveTagInput" size="small"
                @keyup.enter.native="handleInputConfirm" @blur="handleInputConfirm">
              </el-input>
              <el-button v-else class="button-new-tag" size="small" @click="showInput">+ 点击添加</el-button>

              <!-- <el-input v-model="formadd.taskLabelstr" @input="taskLabelstrChange" placeholder="请输入任务标签" /> -->
            </el-form-item>
            <br>
            <!-- <div style="color: rgb(198, 198, 198);margin-left: 80px;margin-top: -20px;"><span
                style="color: rgb(240, 150, 150);">注：</span>
              请使用","来连接标签。（如：商品,名包）</div>
            <div style="margin-left: 80px;margin-top: 10px;"><el-tag v-for="(item, index) in formadd.taskLabelList"
                :key="index" style="margin-right: 10px;" v-if="item">
                {{ item }}
              </el-tag>

            </div> -->

          </el-col>
          <br>

        </el-row>
        <el-row :span="24">

          <el-col :span="12">
            <el-form-item label="奖励金额：" prop="rewardAmt" label-width="120px" :rules="[
              { required: true, message: '请输入奖励金额', trigger: 'blur' },
            ]">
              <el-input v-model="formadd.rewardAmt" placeholder="请输入奖励金额" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="提交时长（分钟）：" prop="submitMins" label-width="200px" :rules="[
              { required: true, message: '请输入提交时长', trigger: 'blur' },
            ]">
              <el-input v-model="formadd.submitMins" placeholder="请输入提交时长" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="补交时长（分钟）：" prop="resubmitMins" label-width="180px" :rules="[
              { required: true, message: '请输入补交时长', trigger: 'blur' },
            ]">
              <el-input v-model="formadd.resubmitMins" placeholder="请输入补交时长" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="预计完成时间（分钟）：" prop="finishMins" label-width="200px" :rules="[
              { required: true, message: '请输入完成时间', trigger: 'blur' },
            ]">
              <el-input v-model="formadd.finishMins" placeholder="请输入完成时间" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="任务要求:" prop="taskDemand" :rules="[
              { required: true, message: '请输入任务要求', trigger: 'blur' },
            ]">
              <div style="border: 1px solid #ccc; width: 800px">
                <Toolbar style="border-bottom: 1px solid #ccc" ref="toolbartag" :editor="editor"
                  :defaultConfig="toolbarConfig" :mode="mode" />
                <Editor style="height: 300px; overflow-y: hidden" v-model="formadd.taskDemand"
                  :defaultConfig="editorConfig" :mode="mode" @onCreated="onCreated" @onChange="onChange" />
              </div>
            </el-form-item>
          </el-col>


          <el-col :span="24">
            <el-form-item label="官方提示:" prop="taskTips" :rules="[
              { required: true, message: '请输入官方提示', trigger: 'blur' },
            ]">
              <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 8 }" placeholder="请输入官方提示"
                v-model="formadd.taskTips">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="任务步骤:" prop="taskStep" :rules="[
              { required: true, message: '请输入任务步骤', trigger: 'blur' },
            ]">
              <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 8 }" placeholder="请输入任务步骤"
                v-model="formadd.taskStep">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="交单格式:" prop="taskFormat" :rules="[
              { required: true, message: '请输入交单格式', trigger: 'blur' },
            ]">
              <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 8 }" placeholder="请输入交单格式"
                v-model="formadd.taskFormat">
              </el-input>
            </el-form-item>
          </el-col>


        </el-row>

        <el-row :span="24">
          <el-col :span="12">
            <el-form-item label="任务二维码:" prop="taskQrCode" :rules="[
              { required: true, message: '请上传任务二维码', trigger: 'blur' },
            ]">
              <imageUpload :limit="1" :file-size="3" v-model="formadd.taskQrCode" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="排序列表" prop="sortNum" :rules="[
              { required: true, message: '请输入排序列表', trigger: 'blur' },
            ]">
              <el-input-number v-model="formadd.sortNum" controls-position="right" :min="0" />
            </el-form-item>
          </el-col>

        </el-row>




        <el-form-item label="任务示例图:" prop="taskImageList">
          <el-upload :limit="9" :action="upload.url" :headers="upload.headers" :file-list="fileList"
            :on-remove="handleRemove" :on-success="handleSuccess" list-type="picture-card" accept="jpeg,.jpg,.png">
            <i class="el-icon-plus"></i>
          </el-upload>
          <el-dialog :visible.sync="dialogVisible">
            <img width="100%" :src="dialogImageUrl" alt="" />
          </el-dialog>
        </el-form-item>



      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确定</el-button>
        <el-button @click="cancel2">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>

// import {
//   uploadimg
// } from "@/api/admin/businessschool";
import { earnTasktype, earnTasklist, saveOrUpdate, earnTask, changeStatus, uploadimg } from "@/api/admin/moneyManage";
import { videoSignature, uploads } from "@/api/admin/video";
import { base64ConvertFile, getVideoBase64 } from "@/utils/index";
import "@wangeditor/editor/dist/css/style.css";
import { Editor, Toolbar } from "@wangeditor/editor-for-vue";
import CTTupload from "@/components/upload/index.vue";
import TcVod from "vod-js-sdk-v6";
import { getToken } from "@/utils/auth";
export default {
  name: "moneyManage",
  components: { CTTupload, Editor, Toolbar },
  data () {
    return {
      taskNumRules: [
        { required: true, message: '请输入数量：', trigger: 'blur' },
        {
          validator: function (rule, value, callback) {
            if (/^[0-9]*$/.test(value) == false) {
              callback(new Error("请输入正确的数字"));
            } else {
              callback();
            }
          }, trigger: 'blur'
        },
      ],
      // 显示搜索条件
      showSearch: true,
      requestUrl: this.$img.requestUrl,
      // tag框
      dynamicTags: [],
      inputVisible: false,
      inputValue: '',
      queryParams: {
        taskId: "",
        typeId: "",
        pageNum: 1,
        pageSize: 10,
        taskName: "",
      },
      lsitarrs: [],

      // 总条数
      total: 0,
      dateRange: [],
      loading: false,
      rewardList: [],
      form: {},
      formadd: {
        hotFlag: 0,
      },
      businessinfouserlist: {},
      open: false,
      addopen: false,
      title: "",
      istype: false,
      resource: "1",
      addtype: 0,
      classification: [
        {
          value: 0,
          label: "待审核",
        },
        {
          value: 1,
          label: "审核通过",
        },
        {
          value: -1,
          label: "审核拒绝",
        },
      ],

      // 上传参数
      upload: {
        // 是否禁用上传
        isUploading: false,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/admin/upload/uploadImg/3",
      },
      fileList: [],
      dialogImageUrl: "",
      dialogVisible: false,

      //富文本
      editor: null,
      html: "",
      toolbarConfig: {
        excludeKeys: [
          "fullScreen", //不显示全屏
          "insertVideo", //不显示插入视频
          "uploadVideo",
        ],
      },
      editorConfig: {
        placeholder: "请输入内容...",
        autoFocus: false,
        MENU_CONF: {
          // 所有的菜单配置，都要在 MENU_CONF 属性下
          // 配置上传图片
          uploadImage: {
            customUpload: this.update,
          },
        },
      },
      mode: "default", // or 'simple'

      hostname:
        window.location.hostname.indexOf("localhost") != -1
          ? "http://djktest.admin.ctt8848.com"
          : window.location.hostname,

    };
  },
  created () {
    this.getList();
    this.getearnTasktype()
  },

  methods: {
    //标签输入
    handleClose (tag) {
      this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1);
      // this.formadd.taskLabelList = this.dynamicTags
      this.$set(this.formadd, 'taskLabelList', this.dynamicTags)
    },

    showInput () {
      this.inputVisible = true;
      this.$nextTick(_ => {
        this.$refs.saveTagInput.$refs.input.focus();
      });
    },

    handleInputConfirm () {
      let inputValue = this.inputValue;
      if (inputValue) {
        this.dynamicTags.push(inputValue);
      }
      // this.formadd.taskLabelList = this.dynamicTags
      this.$set(this.formadd, 'taskLabelList', this.dynamicTags)
      console.log(this.dynamicTags, this.formadd.taskLabelList, "sdassasda")
      this.inputVisible = false;
      this.inputValue = '';
    },
    //获取分类
    async getearnTasktype () {
      await earnTasktype().then((res) => {
        if (res.code == 200) {
          this.classification = res.data;
        }


      });
    },
    //修改是否上架
    recommendChange (row) {
      let text = row.status === 0 ? "停用" : "启用";
      this.$confirm('确认要"' + text + '""' + "该视频的推荐吗?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return changeStatus({
            taskId: row.taskId,
            status: row.status,
          });
        })
        .then(() => {
          this.msgSuccess(text + "成功");
        })
        .catch(function () {
          row.status = row.status == "0" ? 1 : 0;
        });
    },
    //获取发布人列表
    getbusinessInfoUser () {
      return businessInfoUser().then((res) => {
        return res;
      });
    },
    // 新增商品分类
    async handleAdd (Lx, row) {
      this.reset();

      if (Lx == "add") {
        this.addtype = "0";
        this.fileList = [];
        this.formadd.taskImageList = [];
        this.dynamicTags = []
        this.formadd.taskLabelList = [];
        // this.$set(this.formadd, 'taskLabelList',[])

        this.addopen = true;
        this.title = "发布赚钱任务";
      } else {
        this.addtype = "1";
        this.formadd = row;
        this.fileList = [];
        if (row.taskImageList.length > 0) {
          this.istype = false;
          row.taskImageList.forEach((element) => {
            this.fileList.push({
              name: element,
              url: element,
            });
          });
        } else {
          this.istype = true;
        }
        if (row.taskLabelList.length > 0) {
          this.dynamicTags = row.taskLabelList;
        }

        this.addopen = true;
        this.title = "修改赚钱任务";
        // this.$refs.cttUpload.handleRemove();
      }
    },
    // 表单重置
    reset () {
      this.formadd = {};
      this.resetForm("formadd");
    },
    // 表单重置
    reset2 () {
      // this.form = {};
      if (this.istype) {
        try {
          this.$refs.cttUpload.handleRemove();
        } catch (err) {
          console.log(err, "err");
        }
      }

      this.resetForm("formRef");
    },
    // 提交
    submitForm () {



      this.$refs["formadd"].validate((valid) => {
        // 新增
        console.log(this.formadd);

        if (valid) {
          if (this.formadd.taskId != undefined) {
            this.formadd.taskImageList.forEach((element, index) => {
              if (String(element).indexOf("http") != -1) {
                this.formadd.taskImageList[index] = element.slice(
                  this.requestUrl.length,
                  element.length
                );
              }
            });

            saveOrUpdate(this.formadd).then((response) => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.cancel2();
                // this.reset2();
              }
            });
            //修改
          } else {

            console.log(this.formadd)
            saveOrUpdate(this.formadd).then((res) => {
              if (res.code === 200) {
                this.msgSuccess("新增成功");
                this.cancel2();
                // this.reset2();
              }
            });
          }
        } else {
          this.msgError("请填写/选择以上必填信息");
        }
      });
    },
    // 图片删除
    handleRemove (file, fileList) {
      const that = this;
      this.formadd.taskImageList = [];
      console.log(fileList, file);

      fileList.forEach((element) => {

        if (element.response) {
          this.formadd.taskImageList.push(element.response.data.list[0].filePath);
        } else {
          this.formadd.taskImageList.push(element.name);
        }
      });
    },
    // 文件上传成功处理
    handleSuccess (response, file, fileList) {
      this.upload.isUploading = false;

      this.formadd.taskImageList.push(response.data.list[0].filePath);
      this.msgSuccess(response.msg);
    },

    getList () {
      this.loading = true;
      earnTasklist(
        this.queryParams
        // this.addDateRange(this.queryParams, this.dateRange)
      ).then((response) => {
        response.rows.forEach((item, index) => {
          item.taskImageList.forEach((item2, index) => {
            item.taskImageList[index] = this.requestUrl + item2;
          });
        });
        this.rewardList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },




    //审核
    submit () {
      // this.form.status = this.resource;
      this.open = false;
    },

    // 取消按钮
    cancel () {
      this.open = false; //地址弹窗
      // this.addopen = false;
      this.getList();
    },
    cancel2 () {
      this.addopen = false;
      this.reset2();
      this.getList();
    },

    // 多选框选中数据
    handleSelectionChange (selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
      // this.getTotal();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.resetForm("queryForm");
      this.queryParams.beginTime = "";
      this.queryParams.endTime = "";
      this.dateRange = [];
      this.handleQuery();
    },
    handleView (row) {
      this.form = row;
      this.title = "赚钱任务管理详情";
      this.open = true;
    },


    /** 删除按钮操作 */
    handleDelete (row) {
      const userIds = row.taskId ? row.taskId : '';
      this.$confirm(
        '是否确认删除任务ID为"' + userIds + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return earnTask(userIds);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(function () { });
    },
    // 视频上传成功处理
    uploadVideoSuccess (response) {
      this.upload.isUploading = false;
      this.formadd.videoPath = response.data.list[0].filePath;
      // this.form.videoCapture = response.data.list[0].cover;
      // this.form.txVideoId = response.data.list[0].fileId;
      this.msgSuccess(response.msg);
    },
    handleRemoveVideo () {
      this.formadd.videoPath = null;
    },
    //获取视频签名
    getVideoSignature () {
      return videoSignature().then((res) => {
        return res.data;
      });
    },
    //视频上传请求
    uploadHttpRequest (file) {
      const _this = this;
      //必须以函数的形式返回 sdk参数限制
      // 获取视频签名
      const getSignature = async function () {
        return await _this.getVideoSignature();
      };
      // 前文中所述的获取上传签名的函数
      const tcVod = new TcVod({
        getSignature: getSignature,
      });
      const uploader = tcVod.upload({
        mediaFile: file.file, // 这里腾讯云需要获取到file文件里的name，根据你file结构进行填写
      });
      //this.uploaderG = uploader // 定义全局用于取消上传
      // 进度
      uploader.on("media_progress", function (info) {
        //调用onProgress方法来显示进度条，需要传递个对象 percent为进度值
        file.onProgress({ percent: info.percent * 100 });
      });
      // 上传成功
      uploader
        .done()
        .then((doneResult) => {
          getVideoBase64(file.file)
            .then((Result) => {
              let Ifile = base64ConvertFile(Result);
              let formData = new FormData();
              formData.append("file", Ifile, Ifile.name);
              uploads(formData, file)
                .then((response) => {
                  let data = {
                    code: 200,
                    msg: "上传成功",
                    data: {
                      list: [
                        {
                          filePath: doneResult.video.url,
                          cover: response.data.list[0].filePath,
                          fileId: doneResult.fileId,
                        },
                      ],
                    },
                  };
                  file.onSuccess(data);
                })
                .catch((err) => {
                  this.msgError(err);
                });
            })
            .catch((err) => {
              this.msgError("上传失败");
            });
        })
        .catch((err) => {
          this.msgError("上传失败");
        });
    },
    // 富文本上传
    update (file, insertFn) {
      let formData = new FormData();
      formData.append("file", file);
      uploadimg(formData).then((res) => {
        if (res.code == 200) {
          // 最后插入图片
          insertFn(
            this.requestUrl + res.data.list[0].filePath,
            res.data.list[0].fileId,
            this.requestUrl + res.data.list[0].filePath
          );
        } else {
        }
      });
    },
    // 富文本方法
    onCreated (editor) {
      this.editor = Object.seal(editor); // 一定要用 Object.seal() ，否则会报错
      // console.log("uploadImagesssss", this.editor);
    },
    onChange (editor) {
      // this.imghtml = editor.getHtml();
    },

  },
};
</script>
<style  lang="scss">
.eitd {
  padding: 10px 10px;
  border: 1px solid #504949;

}

.eitd img {
  width: 100%;
}
</style>
